import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: Home
  },
  {
    path: '*',
    redirect: '/',
  },

  // 个人中心
  {
    meta: {
      title: '个人中心'
    },
    name: 'personalCenter',
    path: "/personalCenter",
    component: () => import("../views/PersonalCenter/index.vue")
  },
  // 预约检测
  {
    meta: {
      title: '预约检测'
    },
    name: 'makeAnAppointment',
    path: "/makeAnAppointment",
    component: () => import("../views/MakeAnAppointment/index.vue")
  },
  // 到场检测 -  添加车辆
  {
    meta: {
      title: '选择车辆'
    },
    name: 'vehicleInfo',
    path: "/vehicleInfo",
    component: () => import("../views/VehicleInfo/index.vue")
  },
  // 到场检测 - 添加车辆 - 详情
  {
    meta: {
      title: '添加车辆信息'
    },
    name: 'vehicleDetails',
    path: "/vehicleDetails",
    component: () => import("../views/VehicleInfo/details.vue")
  },
  // 到场检测 - 添加车辆 - 选择监测站
  {
    meta: {
      title: '选择监测站'
    },
    path: "/vehicleDetection",
    component: () => import("../views/VehicleInfo/detection.vue")
  },
  // 打印单据
  {
    meta: {
      title: '自助打印单据'
    },
    path: "/printDocuments",
    component: () => import("../views/PrintDocuments/index.vue")
  },
  // 打印单据 - 详情
  {
    meta: {
      title: '打印单据详情'
    },
    name: 'printDetails',
    path: "/printDetails",
    component: () => import("../views/PrintDocuments/details.vue")
  },
  // 订单
  {
    meta: {
      title: '订单详情'
    },
    name: 'order',
    path: "/order",
    component: () => import("../views/Order/index.vue")
  },
  // 支付
  {
    meta: {
      title: '支付'
    },
    name: 'orderPay',
    path: "/orderPay",
    component: () => import("../views/OrderPay/index.vue")
  },
  // 订单进度
  {
    meta: {
      title: '订单进度'
    },
    name: 'progress',
    path: "/progress",
    component: () => import("../views/Progress/index.vue")
  },
  // 服务协议
  {
    meta: {
      title: '服务协议'
    },
    name: 'agreement',
    path: "/vehicleAgreement",
    component: () => import("../views/VehicleInfo/agreement.vue")
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

router.afterEach(route => {
  // 从路由的元信息中获取 title 属性
  if (route.meta.title) {
    document.title = route.meta.title;
    // 如果是 iOS 设备，则使用如下 hack 的写法实现页面标题的更新
    if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
      const hackIframe = document.createElement('iframe');
      hackIframe.style.display = 'none';
      hackIframe.src = '/static/html/fixIosTitle.html?r=' + Math.random();
      document.body.appendChild(hackIframe);
      setTimeout(_ => {
        document.body.removeChild(hackIframe)
      }, 300)
    }
  }
})
export default router;
